<!-- 功能：SNMP报警 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月22日 23:02:20 -->
<template>
  <a-tabs v-model:activeKey="activeKey" type="card" class="y-tabs">
    <a-tab-pane key="snmpGuanLi" tab="SNMP管理">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openXinJianYongHuModal">
                <template #icon>
                  <plus-outlined />
                </template>
                新建用户
              </a-button>
              <!-- 弹窗 - 新建用户 -->
              <xinJianYongHuModal v-model:visible="visibleXinJianYongHuModal"></xinJianYongHuModal>
              <a-button type="link" class="y-btn" @click="qiDongSnmp">
                <template #icon>
                  <PlayCircleOutlined />
                </template>
                启动SNMP
              </a-button>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueSnmpGuanLi">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceSnmpGuanLi" :columns="columnsSnmpGuanLi" class="y-table" :pagination="paginationSnmpGuanLi">
        </a-table>
      </a-card>
    </a-tab-pane>

    <a-tab-pane key="snmpTrapGuanLi" tab="SNMPTrap管理">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openSnmpTrapSheZhiModal">
                <template #icon>
                  <plus-outlined />
                </template>
                SNMPTrap设置
              </a-button>
              <!-- 弹窗 - SNMPTrap设置 -->
              <snmpTrapSheZhiModal v-model:visible="visibleSnmpTrapSheZhiModal"></snmpTrapSheZhiModal>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueSnmpTrapGuanLi">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceSnmpTrapGuanLi" :columns="columnsSnmpTrapGuanLi" class="y-table" :pagination="paginationSnmpTrapGuanLi">
        </a-table>
      </a-card>
    </a-tab-pane>

  </a-tabs>
</template>

<script setup>
import snmpTrapSheZhiModal from './modal/snmpTrapSheZhiModal.vue'
import xinJianYongHuModal from './modal/xinJianYongHuModal.vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { Modal } from 'ant-design-vue'
const activeKey = ref('snmpGuanLi')

// -- SNMP管理
const visibleXinJianYongHuModal = ref(false)

const openXinJianYongHuModal = () => {
  visibleXinJianYongHuModal.value = true
}

const searchValueSnmpGuanLi = ref('')

// 表格列
const columnsSnmpGuanLi = ref([
  {
    title: '用户名',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.name.localeCompare(b.name),
      multiple: 1
    }
  },
  {
    title: '权限',
    dataIndex: 'quXian',
    key: 'quXian',
    align: 'center',
    sorter: {
      compare: (a, b) => a.quXian.localeCompare(b.quXian),
      multiple: 2
    }
  }
])

// 表格数据
const dataSourceSnmpGuanLi = ref([
  {
    key: '1',
    name: 'admin',
    quXian: '只读用户'
  }
])

// 分页
const paginationSnmpGuanLi = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('报警设置 > SNMP管理 >>', page, pageSize)
  }
}

// 启动SNMP
const qiDongSnmp = () => {
  Modal.confirm({
    title: '确认操作',
    icon: h(ExclamationCircleOutlined),
    content: '您确定要启动SNMP?',
    okText: '确定',
    okType: 'danger',
    cancelText: '取消',
    onOk() {
      console.log('OK')
    },
    onCancel() {
      console.log('Cancel')
    }
  })
}
// -- SnmpTrap管理
const visibleSnmpTrapSheZhiModal = ref(false)

const openSnmpTrapSheZhiModal = () => {
  visibleSnmpTrapSheZhiModal.value = true
}

const searchValueSnmpTrapGuanLi = ref('')

// 表格列
const columnsSnmpTrapGuanLi = ref([
  {
    title: '用户ID',
    dataIndex: 'userId',
    key: 'userId',
    align: 'center',
    sorter: {
      compare: (a, b) => a.userId.localeCompare(b.userId),
      multiple: 1
    }
  },
  {
    title: '管理节点IP',
    dataIndex: 'guanLiJieDianIp',
    key: 'guanLiJieDianIp',
    align: 'center',
    sorter: {
      compare: (a, b) => a.guanLiJieDianIp.localeCompare(b.guanLiJieDianIp),
      multiple: 2
    }
  },
  {
    title: '端口',
    dataIndex: 'duanKou',
    key: 'duanKou',
    align: 'center',
    sorter: {
      compare: (a, b) => a.duanKou.localeCompare(b.duanKou),
      multiple: 3
    }
  },
  {
    title: '启用',
    dataIndex: 'qiYong',
    key: 'qiYong',
    align: 'center',
    sorter: {
      compare: (a, b) => a.qiYong.localeCompare(b.qiYong),
      multiple: 4
    }
  }
])

// 表格数据
const dataSourceSnmpTrapGuanLi = ref([
  {
    userId: '1',
    guanLiJieDianIp: '192.168.1.1',
    duanKou: '162',
    qiYong: '启用'
  }
])

// 分页
const paginationSnmpTrapGuanLi = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('报警设置 > SNMPTrap管理 >>', page, pageSize)
  }
}

</script>

<style scoped lang='scss'>
.ant-row {
  margin-bottom: 10px;
}

.y-close-fuzhi-fuwu {
  color: red;
}
</style>